package com.kingdee.eas.custom.common;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.person.PersonFactory;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.client.SysContext;

public class PersonUtil {

	public static AdminOrgUnitInfo getDept(IObjectPK pk)
			throws EASBizException, BOSException {
		return getPersonInfo(pk, "dept.*").getDept();
	}

	public static PersonInfo getPersonInfo(IObjectPK pk, String... fields)
			throws EASBizException, BOSException {
		SelectorItemCollection selectors = new SelectorItemCollection();
		for (int i = 0; i < fields.length; i++) {
			selectors.add(fields[i]);
		}

		return PersonFactory.getRemoteInstance().getPersonInfo(pk, selectors);
	}

	public static PersonInfo getCurrentPerson() {
		return SysContext.getSysContext().getCurrentUserInfo().getPerson();
	}

	public static AdminOrgUnitInfo getCurrentDept() throws EASBizException,
			BOSException {
		return getPersonInfo(new ObjectUuidPK(getCurrentPerson().getId()),
				"dept.*").getDept();
	}
}
